package com.example.nacosserviceconsumer;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 客户端
 */
@FeignClient(name = "service-provider",fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
public interface EchoService {
    @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
    public String echo(@PathVariable String string);
}

/**
 * client配置
 */
class FeignConfiguration{
    @Bean
    public EchoServiceFallback echoServiceFallback() {
        return new EchoServiceFallback();
    }
}

/**
 * 熔断
 */
class EchoServiceFallback implements EchoService {

    @Override
    public String echo(@PathVariable String string) {
        return "echo fallback";
    }
}
